<?php
/* QQ:34734852
 * 业务联系：小鱼
 */
class Core {
	protected $Tpl = object, $Config = array(), $M = object, $post = object, $session = object, $ip = object, $cooke = object, $code = object, $bank = '', $server = object, $curl = object, $files = object;
	protected $json = object, $base = object, $upload = object, $strcode = object;
	public function __construct() {
		if ( file_exists( ROOT . APP . '/Config/Config.ini.php' ) ) {
			include_once ROOT . APP . '/Config/Config.ini.php';
			$this->Config = $Config;
		}
		include_once PATH . 'Class/Template.Class.php';
		$this -> Tpl = new Template;
		$this -> Tpl -> Start( $this -> Config );
		
		include_once PATH . 'Class/DataBase.Class.php';
		$this -> M = new DataBase;
		$this -> M -> Start( $this -> Config );
		
		include_once PATH . 'Class/Form.Class.php';
		$this -> post = new POST;
		$this -> session = new Session;
		
		
		include_once PATH . 'Class/Curl.Class.php';
		$this -> curl   = new curl;
		
	    include_once PATH . 'Class/TaoBaoIPAPI.Class.php';
	    $this -> ip = new TaoBaoIPAPI( $this -> curl );
		
		include_once PATH . 'Class/Cookie.Class.php';
		$this -> cookie = new Cookie;
		
		include_once PATH . 'Class/Verify.Class.php';
		$this -> code = new Verify(array('fontSize' => 40, 'length' => 4, 'imageW' => 0, 'imageH' => 0, 'useImgBg' => false, 'useNoise' => false, 'bg' =>array(255, 255, 255)));
		$this -> bank = $_SERVER['HTTP_REFERER'];

		include_once PATH . 'Class/Server.Class.php';
		$this -> server = new SERVER;
		
		include_once PATH . 'Class/Files_Content.Class.php';
		$this -> files  = new files;
		
		include_once PATH . 'Class/Json.Class.php';
		$this -> json  = new json;
		
		include_once PATH . 'Class/Base.Class.php';
		$this -> base  = new base;
		
		include_once PATH . 'Class/Upload.Class.php';
		$this -> upload  = new Upload;
		
		include_once PATH . 'Class/Str.Class.php';
		$this -> str  = new str;
		
		include_once PATH . 'Class/StringCode.Class.php';
		$this -> strcode  = new strcode;
		
				
		$this -> Tpl -> assign('Mdata', $this -> M );
	}
	
	protected function rurl( $h = 'home', $m = 'index', $c = 'index', $f = '', $out = true ) {
		!empty( $h ) or $h = 'home';
		!empty( $m ) or $m = 'index';
		!empty( $c ) or $c = 'index';
		$f                 = str_replace('?', rand(), $f);
		(SUBDIR != '' && SUBDIR != '/') && $Url = '/' . SUBDIR;
		
		if ( $this->Config['webstatic'] ) {
			$Url .= '/' . $h . '/' . $m . '/' . $c;
		} else {
			$Url .= '/?h=' . $h . '&m=' . $m . '&c=' . $c;
		}
		if ( !empty( $f ) ) {
			if ( $this->Config['webstatic'] ) {
				$s = explode( '&', $f );
				if ( is_array( $s ) ) {
				  foreach( $s as $p ) {
					$g = explode('=', $p );
					$Url .= '/' . $g[0] . '/' . $g[1];
				  }
				}
			} else {
				$Url .= '&' . $f;
			}
		}
		
		unset( $h, $m, $c, $f, $s, $g );
		if ( !$out ) {
		   echo $Url;
		   unset( $out, $Url );	
		} else {
		  unset( $out );
		  return $Url;
		}
	}
	
	
	public function __call( $FunctionName, $FunctionArray ) {
	   $KuoFile = ROOT . APP . '/Class/' . $FunctionName. '.Class.php';
	   file_exists( $KuoFile ) or $this -> ERROR('未找到项目扩展' . $FunctionName );
	   include_once $KuoFile;
	   class_exists( $FunctionName ) or $this -> ERROR('项目扩展'  . $FunctionName . '无法加载');
	   $Obj = new $FunctionName( $FunctionArray[0] );
	   method_exists( $Obj, '__construct' ) && method_exists( $Obj, '__call' ) && method_exists( $Obj, '__set' ) && method_exists( $Obj, '__get' ) or $this -> ERROR('项目扩展' . $FunctionName . '中必须设置 __call， __set， __get， __construct() 方法');
	   unset( $FunctionArray, $FunctionName, $KuoFile );
	   return $Obj;
	}
	
	public static function __callStatic( $FunctionName, $FunctionArray ) {
		EyouPHP::ERROR("未知的静态方法：{$FunctionName} --> " . json_encode( $FunctionArray ));
	}
	
	public function IsPhones() {
		include_once PATH . 'Class/Isphone.Class.php';
		return RequestPhone::isMobile();
	}
	
	public function __get( $key ) {
	   return $this -> Config[ $key ];
	}
	
	public function __set( $key, $val ) {
		$this -> Config[ $key ] = $val;
		unset( $key, $val );
	}
	
	
}
